<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="UTF-8">
    <title th:text="${question.title}">问题详情</title>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <!--这里使用相对路径引入会找不到，引入请求为 /profile/questions,同级目录为 /profile-->
    <!--使用绝对路径引入，如 /css/..-->
    <link rel="stylesheet" href="/css/bootstrap.min.css"/>
    <link rel="stylesheet" href="/css/bootstrap-theme.min.css"/>
    <link rel="stylesheet" href="/css/community.css"/>
    <link rel="stylesheet" href="/css/editormd.preview.min.css"/><!--引入Markdown转html样式-->

    <script src="/js/jquery-3.6.0.min.js"></script>
    <script src="/js/bootstrap.min.js" type="application/javascript"></script>
    <script src="/js/moment.js" type="application/javascript"></script>
    <script src="/js/community.js" type="application/javascript"></script>
    <!--引入Markdown转html js-->
    <script src="/js/editormd.min.js" type="application/javascript"></script>
    <script src="/js/lib/marked.min.js" type="application/javascript"></script>
    <script src="/js/lib/prettify.min.js" type="application/javascript"></script>
</head>
<body>
<div th:insert="navigation::nav"></div>
<div class="container-fluid main profile">
    <div class="row">
        <div class="col-lg-9 col-md-12 col-sm-12 col-xs-12">

            <!--正文-->
            <div class="col-lg-12 col-md-12 col-sm-12 col-xs-12">
                <h4 class="question-title"><span th:text="${question.title}"></span></h4>
                <span class="reply-browse-time">
                作者：<span th:text="${question.user.name}"></span> |
                发布时间：<span th:text="${#dates.format(question.gmtCreate,'yyyy-MM-dd HH:mm')}"></span> |
                阅读数：<span th:text="${question.viewCount}"></span>
            </span>

                <!--描述-->
                <hr class="col-lg-12 col-md-12 col-sm-12 col-xs-12">
                <div class="col-lg-12 col-md-12 col-sm-12 col-xs-12" id="question-view">
                    <!-- Server-side output Markdown text -->
                    <textarea style="display:none;" th:text="${question.description}">### Hello world!</textarea>
                </div>
                <!--使用markdownToHTML，使可以在查看问题时展示markdown语法渲染之后的内容-->
                <script type="text/javascript">
                    $(function () {
                        editormd.markdownToHTML("question-view", {});
                    });
                </script>

                <!--标签-->
                <hr class="col-lg-12 col-md-12 col-sm-12 col-xs-12">
                <div class="col-lg-12 col-md-12 col-sm-12 col-xs-12">
                    <span class="label label-info question-tag" th:each="tag:${question.tag.split(',')}">
                        <span class="glyphicon glyphicon-tags"></span>
                        <span th:text="${tag}" class="question-tag-text"></span>
                    </span>
                </div>

                <!--编辑-->
                <hr class="col-lg-12 col-md-12 col-sm-12 col-xs-12">
                <div class="col-lg-12 col-md-12 col-sm-12 col-xs-12">
                    <a class="community-menu" th:href="@{'/publish/'+${question.id}}"
                       th:if="${session.user != null && session.user.id == question.creator}">
                        <!--这里有个小bug，未登录点击问题user为空直接报异常，未报用户找不到异常，并未处理-->
                        <span class="glyphicon glyphicon-pencil" aria-hidden="true"></span>
                        编辑
                    </a>
                </div>
                <hr class="col-lg-12 col-md-12 col-sm-12 col-xs-12">
            </div>

            <!--回复-->
            <div class="col-lg-12 col-md-12 col-sm-12 col-xs-12">
                <h4><span th:text="${question.commentCount}"></span> 个回复</h4>
                <hr class="col-lg-12 col-md-12 col-sm-12 col-xs-12 question-sp">
                <div class="col-lg-12 col-md-12 col-sm-12 col-xs-12 comments" th:each="comment:${comments}">
                    <div class="media">
                        <div class="media-left">
                            <a href="#">
                                <img class="media-object img-rounded" th:src="${comment.user.avatarUrl}" alt="头像未加载">
                            </a>
                        </div>
                        <div class="media-body">
                            <h5 class="media-heading">
                                <span th:text="${comment.user.name}"></span>
                            </h5>
                            <div>
                                <sapn th:text="${comment.content}"></sapn>
                            </div>
                            <div class="menu">
                                <span class="glyphicon glyphicon-thumbs-up icon"></span>
                                <!--data就是在页面的dom上存放数据，方便前端直接使用。格式：data-自定义key，值为value-->
                                <span th:data-id="${comment.id}" onclick="collapseComments(this)"
                                      class="comment-count-icon">
                                    <span class="glyphicon glyphicon-comment"></span>
                                    <span th:text="${comment.commentCount}"></span>
                                </span>
                                <span class="pull-right"
                                      th:text="${#dates.format(comment.gmtCreate,'yyyy-MM-dd HH:mm')}">
                                </span>
                            </div>
                            <!--二级评论-->
                            <div class="col-lg-12 col-md-12 col-sm-12 col-xs-12 collapse sub-comments"
                                 th:id="${'comment-' + comment.id}">

                                <!--使用js拼接以下页面，显示二级评论-->
                                <!--<div class="col-lg-12 col-md-12 col-sm-12 col-xs-12 comments"
                                     th:each="comment:${comments}">
                                    <div class="media">
                                        <div class="media-left">
                                            <img class="media-object img-rounded" th:src="${comment.user.avatarUrl}"
                                                 alt="头像未加载">
                                        </div>
                                        <div class="media-body">
                                            <h5 class="media-heading" th:text="${comment.user.name}"></h5>
                                            <div th:text="${comment.content}"></div>
                                            <div class="menu">
                                                <span class="pull-right"
                                                      th:text="${#dates.format(comment.gmtCreate,'yyyy-MM-dd HH:mm')}"></span>
                                            </div>
                                        </div>
                                    </div>
                                </div>-->

                                <div class="col-lg-12 col-md-12 col-sm-12 col-xs-12">
                                    <input type="text" class="form-control" placeholder="评论一下..."
                                           th:id="${'input-' + comment.id}">
                                    <button type="button" class="btn btn-success pull-right" onclick="comment(this)"
                                            th:data-id="${comment.id}">评论
                                    </button>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
            </div>

            <!--回复输入框-->
            <div class="col-lg-12 col-md-12 col-sm-12 col-xs-12">
                <h4>提交回复</h4>
                <hr class="col-lg-12 col-md-12 col-sm-12 col-xs-12 question-sp">
                <div class="col-lg-12 col-md-12 col-sm-12 col-xs-12" id="comment_section">
                    <div class="media">
                        <div class="media-left">
                            <a href="#">
                                <img class="media-object img-rounded"
                                     th:src="${session.user != null ? session.user.avatarUrl:'/images/default-avatar.png'}" alt="头像未加载">
                            </a>
                        </div>
                        <div class="media-body">
                            <h5 class="media-heading">
                                <span th:text="${session.user != null ? session.user.name:'匿名用户'}"></span>
                            </h5>
                        </div>
                    </div>
                    <textarea class="form-control comment" rows="6" id="comment_content"></textarea>
                    <input type="hidden" id="question_id" th:value="${question.id}">
                    <button type="button" class="btn btn-success btn-comment" onclick="post()">回复</button>
                </div>
            </div>
        </div>

        <!--右边信息块-->
        <div class="col-lg-3 col-md-12 col-sm-12 col-xs-12">
            <h4>发起人</h4>
            <div class="media">
                <div class="media-left">
                    <a href="#">
                        <img class="media-object img-rounded" th:src="${question.user.avatarUrl}" alt="头像未加载">
                    </a>
                </div>
                <div class="media-body">
                    <h5 class="media-heading">
                        <span th:text="${question.user.name}"></span>
                    </h5>
                </div>
            </div>

            <!--微信号，暂时放其他-->
            <hr class="col-lg-12 col-md-12 col-sm-12 col-xs-12">
            <div class="col-lg-12 col-md-12 col-sm-12 col-xs-12">
                <h4>站长微信</h4>
                <img class="img-thumbnail question-wechat" src="/images/guanggao.png" alt="图片为加载成功"/>
            </div>

            <!--相关问题-->
            <hr class="col-lg-12 col-md-12 col-sm-12 col-xs-12">
            <div class="col-lg-12 col-md-12 col-sm-12 col-xs-12">
                <h4>相关问题</h4>
                <ul class="question-rated">
                    <li th:each="related:${relatedQuestions}">
                        <a th:href="@{'/question/' + ${related.id}}" th:text="${related.title}"></a>
                    </li>
                </ul>
            </div>
        </div>
    </div>
</div>
<div th:insert="~{footer::foot}"></div>
</body>
</html>